"""
自定义异常类
"""
from fastapi import HTTPException, status


class AudioProcessingException(HTTPException):
    """音频处理异常"""
    def __init__(self, detail: str = "音频处理失败"):
        super().__init__(
            status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
            detail=detail
        )


class FileSizeExceededException(HTTPException):
    """文件大小超限异常"""
    def __init__(self, max_size: int):
        super().__init__(
            status_code=status.HTTP_413_REQUEST_ENTITY_TOO_LARGE,
            detail=f"文件过大，最大支持 {max_size // (1024*1024)}MB"
        )


class UnsupportedFileTypeException(HTTPException):
    """不支持的文件类型异常"""
    def __init__(self):
        super().__init__(
            status_code=status.HTTP_400_BAD_REQUEST,
            detail="不支持的文件类型，请上传音频文件"
        )


class InvalidPitchStepsException(HTTPException):
    """无效的音调步数异常"""
    def __init__(self):
        super().__init__(
            status_code=status.HTTP_400_BAD_REQUEST,
            detail="音调步数必须在-24到24之间"
        )


class DatabaseException(HTTPException):
    """数据库异常"""
    def __init__(self, detail: str = "数据库操作失败"):
        super().__init__(
            status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
            detail=detail
        )
